package cn.tedu.supermarket.user.controller;

import cn.tedu.supermarket.base.response.JsonResult;
import cn.tedu.supermarket.user.pojo.dto.UserLoginParam;
import cn.tedu.supermarket.user.pojo.dto.UserQuery;
import cn.tedu.supermarket.user.pojo.vo.UserVO;
import cn.tedu.supermarket.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/user")
public class UserController {
    @Autowired
    UserService userService;

    /**
     * 用户登录
     * POST http://localhost:8080/v1/user/login?username=admin&password=admin
     *
     * @param userLoginParam
     * @return
     */
    @PostMapping("login")
    public JsonResult login(@RequestBody UserLoginParam userLoginParam) {
        log.debug("用户登录：{}", userLoginParam);
        UserVO userVO = userService.login(userLoginParam);
        return JsonResult.ok(userVO);
    }

    // 查询用户信息
    @GetMapping("select")
    public JsonResult selectUser(UserQuery userQuery) {
        log.debug("查询用户信息：{}", userQuery);
        List<UserVO> list = userService.selectUser(userQuery);
        return JsonResult.ok(list);
    }
}